package ar.edu.utn.frsf.cidisi.ginet.generation.preferformalizationpage.views;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

import ar.edu.utn.frsf.cidisi.ginet.generation.preferformalizationpage.Activator;


/**
 * This sample class demonstrates how to plug-in a new
 * workbench view. The view shows data obtained from the
 * model. The sample creates a dummy model on the fly,
 * but a real implementation would connect to the model
 * available either in this or another plug-in (e.g. the workspace).
 * The view is connected to the model using a content provider.
 * <p>
 * The view uses a label provider to define how model
 * objects should be presented in the view. Each
 * view can present the same model objects using
 * different labels and icons, if needed. Alternatively,
 * a single label provider can be shared between views
 * in order to ensure that objects of the same type are
 * presented in the same way everywhere.
 * <p>
 */

public class View extends ViewPart {

	/**
	 * The ID of the view as specified by the extension.
	 */
	public static final String ID = "ar.edu.utn.frsf.cidisi.ginet.generation.preferencepage1.views.View";

	  private Label label;

	  public void createPartControl(Composite parent) {
	    IPreferenceStore preferenceStore = Activator.getDefault()
	        .getPreferenceStore();
	    String string = preferenceStore.getString("MySTRING1");

	    label = new Label(parent, SWT.NONE);
	    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
	        false));
	    label.setText(string);
	    // Add change listener to the preferences store so that we are notified
	    // in case of changes
	    Activator.getDefault().getPreferenceStore()
	        .addPropertyChangeListener(new IPropertyChangeListener() {
	          @Override
	          public void propertyChange(PropertyChangeEvent event) {
	            if (event.getProperty() == "MySTRING1") {
	              label.setText(event.getNewValue().toString());
	            }
	          }
	        });
	  }

	  public void setFocus() {
	  }
}